package cloudContact;

import java.util.Hashtable;

import org.scribe.builder.ServiceBuilder;
import org.scribe.builder.api.GoogleApi;
import org.scribe.oauth.OAuthService;

import com.google.gdata.client.authn.oauth.GoogleOAuthParameters;

public class GoogleConstant {

	public static final String AUTHORIZE_URL = "https://www.google.com/accounts/OAuthAuthorizeToken?oauth_token=";
	public static final String CONSUMER_KEY = "cloudctac.dyndns.org";
	public static final String CONSUMER_SECRET = "CaThGFUNRxyNAO8srvoGAC-T";
	public static final String SCOPE = "https://www.google.com/m8/feeds/";
	public static final String CALLBACK_URL = "https://cloudctac.dyndns.org/CloudContact/GoogleOAuthCallback";

	private GoogleConstant() {
	}

	private static OAuthService service = null;

	public static OAuthService getOAuthService() {
		if (service == null) {
			service = new ServiceBuilder().provider(GoogleApi.class)
					.apiKey(GoogleConstant.CONSUMER_KEY)
					.apiSecret(GoogleConstant.CONSUMER_SECRET)
					.callback(GoogleConstant.CALLBACK_URL)
					.scope(GoogleConstant.SCOPE).build();
		}
		return service;
	}

	private static Hashtable<Integer, GoogleOAuthParameters> oauthParamCol = new Hashtable<Integer, GoogleOAuthParameters>();

	public static synchronized GoogleOAuthParameters getGoogleOAuthParameters(
			String authToken, String authTokenSecret, int userId) {

		GoogleOAuthParameters oauthParameters = oauthParamCol.get(userId);

		if (oauthParameters == null) {
			oauthParameters = new GoogleOAuthParameters();

			oauthParameters.setOAuthConsumerKey(GoogleConstant.CONSUMER_KEY);
			oauthParameters
					.setOAuthConsumerSecret(GoogleConstant.CONSUMER_SECRET);
			oauthParameters.setOAuthToken(authToken);
			oauthParameters.setOAuthTokenSecret(authTokenSecret);
		}
		return oauthParameters;
	}
}
